﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCamera : MonoBehaviour
{

    public float scalePower = 25f;
    public float movePower = 1f;
    public float scaleorthographicPower = 5f;

    Camera mainCamera;
    Transform mainCameraX;
    Transform mainCameraY;

    // Use this for initialization
    void Start()
    {
        mainCamera = GetComponent<Camera>();
        mainCameraX = mainCamera.transform.parent;
        mainCameraY = mainCamera.transform.parent.parent;

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(2))
        {
            if (mainCamera.orthographic)
            {

            }
            else
            {
                mainCameraY.position += mainCamera.transform.TransformDirection(
          new Vector3(
              -Input.GetAxis("Mouse X") * (movePower + movePower * Mathf.Abs(mainCamera.transform.localPosition.z) * 0.05f),
          -(Input.GetAxis("Mouse Y") * (movePower + movePower * Mathf.Abs(mainCamera.transform.localPosition.z) * 0.05f)), 0));


            }

            //mainCameraX.position += mainCamera.transform.TransformDirection(
            //new Vector3(-Input.GetAxis("Mouse X"), 0, 0));
        }
        if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
            //if (ConfigCamera.isUI)
            //{

            //}
            //else
            {
                if (mainCamera.orthographic)
                {
                    mainCamera.orthographicSize = Mathf.Clamp(mainCamera.orthographicSize - scaleorthographicPower * Input.GetAxis("Mouse ScrollWheel"), 1, 50);
                }
                else
                {
                    mainCamera.transform.localPosition += new Vector3(0, 0, scalePower * Input.GetAxis("Mouse ScrollWheel"));
                }
            }
        }
        if (Input.GetMouseButton(1))
        {
            mainCameraX.localRotation *=
               Quaternion.Euler(new Vector3(-Input.GetAxis("Mouse Y") * 2, 0, 0)
           );
            mainCameraY.rotation *=
                Quaternion.Euler(new Vector3(0, Input.GetAxis("Mouse X") * 2, 0)
            );
        }
    }

}
